/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JPanelIntercanvi.java
 *
 * Created on 19-may-2010, 18:11:56
 */

package edu.ieslaferreria.creditsintesis.builders.Swing;

import edu.ieslaferreria.creditsintesis.logicgame.Parameter;
import edu.ieslaferreria.creditsintesis.logicgame.actions.RmiEvent;
import edu.ieslaferreria.creditsintesis.rmi.Client;
import edu.ieslaferreria.creditsintesis.rmi.EventChangePanel;
import edu.ieslaferreria.creditsintesis.rmi.EventIniciarInteraccion;
import edu.ieslaferreria.creditsintesis.rmi.EventPanelsInteractionTwoPlayersListener;
import edu.ieslaferreria.creditsintesis.rmi.GameEvent;
import edu.ieslaferreria.creditsintesis.rmi.GameEventInteracctionTwoPanels;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;

/**
 *
 * @author Administrador
 */
public class JPanelIntercanvi extends JPanelGame{
  
    /** Creates new form JPanelIntercanvi */
    public JPanelIntercanvi() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jComboBoxkindExchange = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jListExtras = new javax.swing.JList();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextPaneExtras = new javax.swing.JTextPane();
        jTextFieldExchangeAnotherPlayer = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jButtonEnviar = new javax.swing.JButton();
        jButtonVolver = new javax.swing.JButton();

        jComboBoxkindExchange.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBoxkindExchange.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxkindExchangeActionPerformed(evt);
            }
        });

        jLabel1.setText("Que vols proposar de intercanviar??");

        jListExtras.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(jListExtras);

        jLabel2.setText("Quin/a?");

        jScrollPane2.setViewportView(jTextPaneExtras);

        jTextFieldExchangeAnotherPlayer.setText("jTextField1");

        jLabel3.setText("Intecanvi proposat per l'altre player");

        jButtonEnviar.setText("Enviar");
        jButtonEnviar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEnviarActionPerformed(evt);
            }
        });

        jButtonVolver.setText("Volver");
        jButtonVolver.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonVolverActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jComboBoxkindExchange, javax.swing.GroupLayout.PREFERRED_SIZE, 255, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(41, 41, 41))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel1)
                            .addGap(123, 123, 123))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 290, Short.MAX_VALUE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(259, 259, 259)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel3)
                        .addComponent(jTextFieldExchangeAnotherPlayer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 275, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(79, 79, 79)
                        .addComponent(jButtonVolver, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(19, 19, 19)
                        .addComponent(jButtonEnviar)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBoxkindExchange, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldExchangeAnotherPlayer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButtonEnviar)
                            .addComponent(jButtonVolver))))
                .addContainerGap(21, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBoxkindExchangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxkindExchangeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBoxkindExchangeActionPerformed

    private void jButtonEnviarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonEnviarActionPerformed
        // TODO add your handling code here:

        /*enviar al otro player*/
    }//GEN-LAST:event_jButtonEnviarActionPerformed

    private void jButtonVolverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonVolverActionPerformed
try {
/*meto cliente en un arraylist...los eventos tienen arraylist, quizas seria bastante un string*/
            ArrayList<String> alias = new ArrayList();
            alias.add(getClient().getNom());


             /*envio el canvio a mi mismo con boolean de respuesta a false*/
            getClient().onMessage(new EventChangePanel(null,A_PANELINICI,false,alias,getPontPanel()));

   /*envio por el puente de la partida a todos los players de susodicha menos yo,
   * enviando mi nombre para que sepan a quien NO debe enviarselo*/
            this.getPontPanel().send(new EventChangePanel(null,A_PANELMENUWAIT,false,alias,getPontPanel()));
        } catch (RemoteException ex) {
            Logger.getLogger(JPanelCompetition2.class.getName()).log(Level.SEVERE, null, ex);
        }



try {
/*meto cliente en un arraylist...los eventos tienen arraylist, quizas seria bastante un string*/
            ArrayList<String> alias = new ArrayList();
            alias.add(getClient().getNom());


             /*envio el canvio a mi mismo con boolean de respuesta a false*/
            getClient().onMessage(new EventChangePanel(null,A_PANELINICI,false,alias,getPontPanel()));

   /*envio por el puente de la partida a todos los players de susodicha menos yo,
   * enviando mi nombre para que sepan a quien NO debe enviarselo*/
            this.getPontPanel().send(new EventChangePanel(null,A_PANELINICI,false,alias,getPontPanel()));
        } catch (RemoteException ex) {
            Logger.getLogger(JPanelCompetition2.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event_jButtonVolverActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonEnviar;
    private javax.swing.JButton jButtonVolver;
    private javax.swing.JComboBox jComboBoxkindExchange;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JList jListExtras;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField jTextFieldExchangeAnotherPlayer;
    private javax.swing.JTextPane jTextPaneExtras;
    // End of variables declaration//GEN-END:variables

      
    public void update(Map<String, List<String>> opcions,ArrayList<String> extras) {
      this.jComboBoxkindExchange.setModel(new DefaultComboBoxModel(opcions.get(OPCIO_BASICA).toArray()));
      this.jListExtras.setModel(new DefaultComboBoxModel(extras.toArray()));
     
    }
    
}

